package com.haoxi.gateway.cmppmsg;

import com.haoxi.gateway.util.TypeConvert;

public class CMPPActiveRepMessage extends CMPPMessage {
    private String outStr;

    public CMPPActiveRepMessage(int success_Id) throws IllegalArgumentException {
        if (success_Id < 0 || success_Id > 255) {
            throw new IllegalArgumentException(
                    "The parameter of response message for answering the active message sent by SMC is wrong:success_Id less than 0 or larger than 255.");
        } else {
            int len = 13;
            buf = new byte[len];
            TypeConvert.int2byte(len, buf, 0);
            TypeConvert.int2byte(CMPPCommon.CMPP_ACTIVE_RESP, buf, 4);
            buf[12] = (byte) success_Id;
            outStr = ",SuccessId=".concat(String.valueOf(buf[12]));
        }
    }

    public CMPPActiveRepMessage(byte buf[]) throws IllegalArgumentException {
        super.buf = new byte[5];
        if (buf.length != 5) {
            throw new IllegalArgumentException(
                    "The message that is sent by SMC is wrong");
        } else {
            System.arraycopy(buf, 0, super.buf, 0, 5);
            sequence_Id = TypeConvert.byte2int(super.buf, 0);
            outStr = ",SuccessId=".concat(String.valueOf(buf[4]));
        }
    }

    public int getSuccessId() {
        return buf[4];
    }

    public String toString() {
        StringBuffer tmpBuf = new StringBuffer("CMPP_Active_Test_REP: ");
        tmpBuf.append("Sequence_Id=").append(getSequenceId());
        tmpBuf.append(outStr);
        return tmpBuf.toString();
    }

    public int getCommandId() {
        return CMPPCommon.CMPP_ACTIVE_RESP;
    }
}
